<?php

namespace app\admin\controller;

use app\model\MenuModel;
use app\service\MenuService;
use think\Db;
use think\Session;

class Menu extends Base
{
    protected $service;

    protected $model;

    public function __construct(MenuService $menuService)
    {
        parent::__construct();
        $this->service = $menuService;
        $this->model = MenuModel::class;
    }


    /**
     * @return \think\response\View
     */
    public function index()
    {
//        $info = $this->service->get(new $this->model);
        $adminInfo = Session::get('admin_info');
        $name = $adminInfo['login_number'];
        $adminId = $adminInfo['id'];
        $menuList = Db::name('admin')
            ->field('m.*')
            ->alias('a')
            ->join('role r','r.id = a.role_id')
            ->join('re_role rr','rr.role_id = a.role_id')
            ->join('menu m','m.id = rr.menu_id')
            ->where(['a.id'=>$adminId])
            ->select();
        $info = $this->service->setMenu($menuList);
        $this->assign('name',$name);
        $this->assign('info',$info);
        return view();
    }

    public function table()
    {
        return view();
    }

    public function main()
    {
        return view();
    }




}